////////////////////////////////////////////////////////////////////////////
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
//  Copyright (c) Kentaro Sekimoto All rights reserved.
//
////////////////////////////////////////////////////////////////////////////

#include "tinyhal.h"
#include "..\..\..\..\..\DeviceCode\Targets\Native\FM3\DeviceCode\FM3.h"
//#include "mcu.h"

#define LCD_ADDRESS (*(volatile unsigned char*)0x61000000)
#define LCD_VALUE   (*(volatile unsigned char*)0x61000002)

void P8_Initialize(void)
{
    // Reset
    FM3_GPIO->ADE &= 0xFFF7;    // P13 NOT Analog
    FM3_GPIO->PFR1 &= 0xFFF7;   // P13 GPIO
    FM3_GPIO->DDR1 |= 0x0008;   // P13 output
}

void LCD_nRESET(int n)
{
    if (n)
        FM3_GPIO->PDOR1 |= 0x0008;
    else
        FM3_GPIO->PDOR1 &= 0xFFF7;
}

void P8_LCD_cmd(volatile unsigned short index)
{
    LCD_ADDRESS = (unsigned char)(index >> 8);
    LCD_ADDRESS = (unsigned char)(index >> 0);
    return;
}

void P8_LCD_dat(volatile unsigned short data)
{
    LCD_VALUE = (unsigned char)(data >> 8);
    LCD_VALUE = (unsigned char)(data >> 0);
}

unsigned short P8_LCD_read_dat(volatile unsigned short index)
{
    volatile unsigned short data;
    LCD_ADDRESS = (unsigned char)(index >> 8);
    LCD_ADDRESS = (unsigned char)(index >> 0);
    data = (unsigned short)LCD_VALUE;
    data = (data << 8) + (unsigned short)LCD_VALUE;
    return data;
}
//--//

